from .celery import app


@app.task
def banner_update():
    # 需要cache、model、serilizer模块
    from django.core.cache import cache
    from home import serializer, models
    from django.conf import settings
    queryset_banner = models.Banner.objects.filter(
        is_delete=False,
        is_show=True
    ).order_by('orders')[:settings.BANNER_COUNTER]
    serializer_banner = serializer.BannerModelSerializer(instance=queryset_banner, many=True)

    # print(serializer_banner.data)
    for banner in serializer_banner.data:
        banner['img'] = 'http://127.0.0.1:8000'+banner['img']
    cache.set('banner_list', serializer_banner.data)

    import time
    time.sleep(1)
    banner_list = cache.get('banner_list')
    print(banner_list)
    return True
